package com.rmfyzxfw.caseprocess.config.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @description: mybatis-plus属性自动填充
 * @Author: GYW  742926306@qq.com
 * @Date: 2023/6/7 11:25
 */
@Component
@Slf4j
public class AutoFillDataHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //TODO   用户信息
        String idCard = "";
        if (Objects.nonNull(idCard)) {
            this.strictInsertFill(metaObject, "createBy", String.class, idCard);
            this.strictInsertFill(metaObject, "updateBy", String.class, idCard);
        }
        this.strictInsertFill(metaObject, "isDel", Long.class, 0L);
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        String idCard = "";
        if (Objects.nonNull(idCard)) {
            this.strictInsertFill(metaObject, "updateBy", String.class, idCard);
        }
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}
